home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
C
/
Comet2.1.3.cpt
/
emlib
/
h19key.c
< prev
next >
Wrap
Text File
|
1991-07-31
|
8KB
|
501 lines
/* Copyright Cornell University 1986. All rights are reserved. */
#include <em.h>
#include <h19.h>
#ifdef H19INPUT
/* following are the line 25 routines, which draw above the emulator screen where the controls sit */
Rect charrect;
h19key()
{
short thechar;
EventRecord evt;
GetNextEvent(keyDownMask|autoKeyMask, &evt);
if (evt.what == nullEvent)
return(NONE);
else {
thechar = evt.message & 0xff;
if (evt.modifiers & cmdKey) {
if (thechar == '`' || thechar == '~')
;
else {
/* command key down -- make it a control character */
if (thechar == '1')
thechar = F10;
else
thechar &= 0x1f;
}
}
if (thechar == BS)
if (!ba_bs)
thechar = DELETE;
return(thechar);
}
}
h19line(buf, length, echo)
char *buf;
unsigned length;
char echo;
{
short thechar;
EventRecord evt;
unsigned current;
current = 0;
setcursor();
emprep();
while (TRUE) {
while (!GetNextEvent(keyDownMask|autoKeyMask, &evt))
;
thechar = evt.message & 0xff;
if (evt.modifiers & cmdKey) {
/* command key down, interpret control chars */
switch (thechar) {
case 'U':
case 'u':
/* clear entry */
if (echo) {
while (current) {
em(BS);
em(' ');
em(BS);
--current;
}
setcursor();
}
else
current = 0;
continue;
case 'C':
case 'c':
/* completely punt this line */
while (current) {
em(BS);
em(' ');
em(BS);
--current;
}
setcursor();
buf[0] = '\0';
emend();
return(thechar & 0x1f);
}
}
switch (thechar) {
case CR:
buf[current] = '\0';
emend();
return(thechar);
case BS:
if (current) {
if (echo) {
em(BS);
em(' ');
em(BS);
setcursor();
}
--current;
length++;
}
break;
default:
;
}
if (thechar < 32)
/* don't incorporate control chars */
continue;
if (!--length) {
/* no space in destination buffer */
beep();
continue;
}
if (echo) {
em(thechar);
setcursor();
}
buf[current++] = thechar;
}
emend();
}
get25line(buf, length, echo)
char *buf;
unsigned length;
char echo;
{
short thechar;
EventRecord evt;
unsigned current;
Point openloc;
struct fontsave ofont;
savefont(&ofont);
current = 0;
GetPen(&openloc);
MoveTo(emdp->penloc25.h, emdp->penloc25.v);
charrect.top = emdp->penloc25.v - 8;
charrect.left = emdp->penloc25.h - 1;
charrect.bottom = emdp->penloc25.v + 2;
charrect.right = emdp->penloc25.h + 5;
InvertRect(&charrect);
while (TRUE) {
while (!GetNextEvent(keyDownMask|autoKeyMask, &evt))
;
thechar = evt.message & 0xff;
if (evt.modifiers & cmdKey) {
/* command key down, interpret control chars */
switch (thechar) {
case 'U':
case 'u':
/* clear entry */
if (echo) {
while (current) {
do25char(BS);
--current;
}
}
else
current = 0;
continue;
case 'C':
case 'c':
/* completely punt this line */
while (current) {
do25char(BS);
--current;
}
buf[0] = '\0';
emend();
return(thechar & 0x1f);
}
}
switch (thechar) {
case CR:
buf[current] = '\0';
EraseRect(&charrect);
/* move cursor to beginning? */
emend();
return(thechar);
case BS:
if (current) {
if (echo) {
do25char(BS);
}
--current;
length++;
}
break;
default:
;
}
if (thechar < 32)
/* don't incorporate control chars */
continue;
if (!--length) {
/* no space in destination buffer */
beep();
continue;
}
if (echo) {
do25char(thechar);
}
buf[current++] = thechar;
}
/* reset the pen location */
thePort->pnLoc.h = openloc.h;
thePort->pnLoc.v = openloc.v;
restorefont(&ofont);
}
do25char(thechar)
char thechar;
{
if (thechar == BS) {
EraseRect(&charrect); /* blank cursor */
charrect.left -= FONTWIDTH;
charrect.right -= FONTWIDTH;
EraseRect(&charrect); /* blank deleted char */
InvertRect(&charrect); /* invert cursor */
Move(-FONTWIDTH, 0);
}
else {
EraseRect(&charrect); /* blank cursor */
DrawChar(thechar);
charrect.left += FONTWIDTH;
charrect.right += FONTWIDTH;
InvertRect(&charrect); /* invert cursor */
}
}
#endif
/* the 25th line is above the emulator screen sharing space with
some buttons */
restore25()
{
emdp->line25[0] = '\0'; /* so controls drawn on refresh */
if (emdp->emwindow == NULL)
return;
emdp->controlschanged = TRUE;
InvalRect(&emdp->toprect);
}
/* clear the 25th line */
clr25()
{
emdp->line25[0] = '\0'; /* so controls drawn on refresh */
if (emdp->emwindow == NULL)
return;
EraseRect(&emdp->toprect);
}
/* is the 25th line on? */
line25on(twp)
struct winds * twp;
{
if (twp->line25[0] != '\0')
return(TRUE);
else
return(FALSE);
}
/* redraw the 25th line */
line25refresh()
{
struct fontsave ofont;
savefont(&ofont);
MoveTo(6, -12);
DrawText(emdp->line25, 0, strlen(emdp->line25));
restorefont(&ofont);
}
/* Print an error message on the 25th line, setting a timer which will cause
it to be wiped out in 5 seconds. */
prerr25(strp)
char *strp;
{
if (!emwindow)
return;
pr25(0, strp);
set25(5);
}
/* print an error from a context other than emdp, and don't erase it */
prerrint25(twp, strp)
struct winds * twp;
char *strp;
{
struct winds * oemdp;
if (!emwindow)
return;
oemdp = emdp;
if (twp != oemdp) {
getcontext(twp);
}
pr25(0, strp);
if (twp != oemdp) {
/* restore emdp context */
getcontext(oemdp);
}
}
/* print on line 25 at a given x */
prat25(s, offset)
char *s;
unsigned int offset;
{
register int count;
register char * linep;
int strlength;
struct fontsave ofont;
GrafPtr oport;
if (offset > LINE25LEN)
return(-1);
/* get rid of nulls in the middle */
for (count = 0, linep = emdp->line25; count++ < offset; linep++) {
if (*linep == '\0')
*linep = ' ';
}
strlength = strlen(s);
if ((offset + strlength) > LINE25LEN) {
strlength = LINE25LEN - offset;
}
/* copy the string */
strncpy(linep, s, (int) strlength);
if (emwindow == NULL)
return;
GetPort(&oport);
SetPort(emwindow);
savefont(&ofont);
/* draw it */
MoveTo((short) (FONTWIDTH * offset) + 6, -12);
DrawText(s, 0, strlength);
restorefont(&ofont);
SetPort(oport);
}
/* print a string starting at offset characters on the 25th line */
pr25(offset, strp)
unsigned int offset;
char *strp;
{
Rect eraserect;
short bitoffset;
int strlength;
Point openloc;
register int count;
register char * linep;
struct fontsave ofont;
GrafPtr oport;
if (offset >= LINE25LEN)
return(-1);
strlength = strlen(strp);
if ((offset + strlength) > LINE25LEN) {
strlength = LINE25LEN - offset - 1;
}
/* get rid of everything in the middle */
for (count = 0, linep = emdp->line25; count++ < offset; linep++) {
/* if (*linep == '\0') */
*linep = ' ';
}
/* terminate it */
emdp->line25[offset + strlength] = '\0';
/* copy the string */
strncpy(linep, strp, (int) strlength);
if (emwindow == NULL)
return;
GetPort(&oport);
SetPort(emwindow);
bitoffset = FONTWIDTH * offset + 6;
savefont(&ofont);
/* save old pen */
GetPen(&openloc);
if (offset == 0) {
/* erase the whole top control area */
EraseRect(&emdp->toprect);
}
else {
/* erase the area that will be drawn on */
eraserect.top = -20;
eraserect.left = emdp->toprect.left + bitoffset;
eraserect.bottom = -5;
eraserect.right = emdp->toprect.right;
EraseRect(&eraserect);
}
/* draw it */
MoveTo(bitoffset, -12);
DrawText(strp, 0, strlength);
/* save the most recent penloc for get25line() */
emdp->penloc25.h = thePort->pnLoc.h;
emdp->penloc25.v = thePort->pnLoc.v;
/* reset the pen location */
thePort->pnLoc.h = openloc.h;
thePort->pnLoc.v = openloc.v;
restorefont(&ofont);
SetPort(oport);
/* guarantee it won't get cleared by a timer entry */
tm_clear(emdp->timer25);
}
/* timer routine to restore the buttons over line 25 */
reset25(windp)
struct winds * windp;
{
GrafPtr oport;
struct winds * owp;
owp = emdp;
getcontext(windp);
GetPort(&oport);
SetPort(windp->emwindow);
if (windp->connopen)
restore25();
tm_clear(windp->timer25);
SetPort(oport);
getcontext(owp);
}
/* set a timer to clear line 25 so we can use the buttons */
set25(secs)
int secs;
{
tm_set(secs, reset25, emdp, emdp->timer25);
}